package com.yh.workbill.ui.home;

import com.yh.workbill.model.WorkBill;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.crypto.interfaces.PBEKey;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class HomeViewModel extends ViewModel {

    public MutableLiveData<List<WorkBill>> workBilldatas;

    public MutableLiveData<List<WorkBill>> getWorkBilldata() {
        if (workBilldatas == null) {
            workBilldatas = new MutableLiveData<>();
        }
        return workBilldatas;
    }

    public void addworkBilldatas(int index, WorkBill... workBills) {
        List<WorkBill> value = workBilldatas.getValue();
        if (value == null) {
            value = new ArrayList<>();
        }
        List<WorkBill> temp = Arrays.asList(workBills);
        if (index == 0) {//新增
            value.addAll(0, temp);
            workBilldatas.postValue(value);
        } else {//更多
            value.addAll(temp);
            workBilldatas.postValue(value);
        }
    }

    public void addNoworkBilldata() {
        workBilldatas.postValue(new ArrayList<>());
    }

    public void update() {
        List<WorkBill> value = workBilldatas.getValue();
        if (value == null) {
            value = new ArrayList<>();
        }
        workBilldatas.postValue(value);
    }

}